Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unthunk each element in ∇eachslice #814

Merged
merged 3 commits into from
Jan 1, 2025

Conversation

pxl-th
Copy link
Contributor

@pxl-th pxl-th commented Dec 25, 2024

This is required to make Zygote work with thunks (using this PR FluxML/Zygote.jl#966).

MWE:

x = ones(Float32, 3, 2)
Zygote.gradient(x) do x
    sum(map(norm, eachcol(x)))
end

Returns:

(Float32[0.0 0.0; 0.0 0.0; 0.0 0.0],)

The reason this happens is because ZBack no longer unthunks Thunks when being called (in wrap_chainrules_output), so rrule for eachcol receives dy as:

Vector{ChainRulesCore.InplaceableThunk{ChainRulesCore.Thunk{ChainRules.var"#1071#1074"{Float32, SubArray{Float32, 1, Matrix{Float32}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}, Float32}}, ChainRules.var"#1070#1073"{Float32, SubArray{Float32, 1, Matrix{Float32}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}, Float32}}}

Where each element of Vector is produced by norm_pullback_2.
While previously due to unthunking in ZBack we'd get for dy:

Vector{Vector{Float32}}

And so the execution of ∇eachslice woudn't terminate here.

@oxinabox
Copy link
Member

This seems fine and correct,
can we introduce a test that has what failed before and test it passes now?

@pxl-th
Copy link
Contributor Author

pxl-th commented Dec 29, 2024

Done. Also bumped patch version so that we could tag a release and Zygote could pick it up.

@oxinabox oxinabox merged commit 02e21ba into JuliaDiff:main Jan 1, 2025
4 of 10 checks passed
@pxl-th pxl-th deleted the pxl-th/eachslice branch January 1, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants